package cn.zhj.base.mvp.ui.base

import android.view.Gravity
import android.view.ViewGroup
import cn.zhj.mvpart.mvp.BaseFragment
import cn.zhj.mvpart.mvp.IPresenter
import cn.zhj.base.R
import cn.zhj.base.mvp.ui.view.CommonDialog

abstract class BaseModuleFragment<out P: IPresenter> : BaseFragment<P>() {
    private var dialogLoading: CommonDialog? = null


    override fun showLoading() {
        if (dialogLoading != null && dialogLoading!!.isShowing()) {
            dialogLoading!!.dismiss()
        }
        dialogLoading = getContext()?.let {
            CommonDialog(
                it,
                R.layout.dialog_loading,
                Gravity.CENTER
                ,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT
            )
        }
        dialogLoading!!.setCancelable(false)
        dialogLoading!!.show()
    }

    override fun hideLoading() {
        if (dialogLoading != null && dialogLoading!!.isShowing) {
            dialogLoading!!.dismiss()
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        if (dialogLoading != null && dialogLoading!!.isShowing) {
            dialogLoading!!.dismiss()
            dialogLoading = null
        }
    }
}